<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>C语言⭐数据类型 | 小李博客</title><meta name="keywords" content="C语言"><meta name="author" content="小李博客"><meta name="copyright" content="小李博客"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="C语言结构123456#include&lt;stdio.h&gt;  &#x2F;&#x2F;编译预处理指令int main()		&#x2F;&#x2F;定义主函数 &amp;#123;		&#x2F;&#x2F;函数开始的标志   printf(&quot;HelloWorld!&quot;); &#x2F;&#x2F;输出语句   return 0; 	&#x2F;&#x2F;函数执行完毕时返回函数值0&amp;#125;		&#x2F;&#x2F;函数结束的标志   一个程序由一个或多个源程序文件组成。①预处理指令。（#">
<meta property="og:type" content="article">
<meta property="og:title" content="C语言⭐数据类型">
<meta property="og:url" content="http://xiaoliblog.cn/page/C04.html">
<meta property="og:site_name" content="小李博客">
<meta property="og:description" content="C语言结构123456#include&lt;stdio.h&gt;  &#x2F;&#x2F;编译预处理指令int main()		&#x2F;&#x2F;定义主函数 &amp;#123;		&#x2F;&#x2F;函数开始的标志   printf(&quot;HelloWorld!&quot;); &#x2F;&#x2F;输出语句   return 0; 	&#x2F;&#x2F;函数执行完毕时返回函数值0&amp;#125;		&#x2F;&#x2F;函数结束的标志   一个程序由一个或多个源程序文件组成。①预处理指令。（#">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png">
<meta property="article:published_time" content="2021-01-15T02:38:17.871Z">
<meta property="article:modified_time" content="2021-03-20T10:07:15.696Z">
<meta property="article:author" content="小李博客">
<meta property="article:tag" content="C语言">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png"><link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/xiaoliblog/image@6b5e7ef72be1c8973d94e5a9c49accbf775ad820/2021/02/01/c485da031fe0e464d04eaba8a66c4a8f.png"><link rel="canonical" href="http://xiaoliblog.cn/page/C04"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.js" defer></script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: {"appId":"RTG4CPNBLJ","apiKey":"f1745bdad68ceec57653b78244fe332c","indexName":"MyBlogIndex","hits":{"per_page":6},"languages":{"input_placeholder":"搜索文章","hits_empty":"找不到您查询的内容：${query}","hits_stats":"找到 ${hits} 条结果，用时 ${time} 毫秒"}},
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":100,"languages":{"author":"作者: 小李博客","link":"链接: ","source":"来源: 小李博客","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"top-center"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-03-20 18:07:15'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><link rel="stylesheet" href="/css/MyStyle/MyStyle.css" media="defer" onload="this.media='all'"/><link rel="stylesheet" href="/css/MyStyle/tagStyle.css" media="defer" onload="this.media='all'"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zykjofficial/zykjresource@master/css/font-awesome-animation.min.css" media="defer" onload="this.media='all'"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/plugins.min.css" media="defer" onload="this.media='all'"><meta name="generator" content="Hexo 5.2.0"><link rel="alternate" href="/atom.xml" title="小李博客" type="application/atom+xml">
</head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@6b5e7ef72be1c8973d94e5a9c49accbf775ad820/2021/02/01/c485da031fe0e464d04eaba8a66c4a8f.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">210</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">38</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">56</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/box/"><i class="fa-fw fa fa-briefcase"></i><span> 工具箱</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-book"></i><span> 找文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-address-card"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小李博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/box/"><i class="fa-fw fa fa-briefcase"></i><span> 工具箱</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-book"></i><span> 找文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-address-card"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">C语言⭐数据类型</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-01-15T02:38:17.871Z" title="发表于 2021-01-15 10:38:17">2021-01-15</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-03-20T10:07:15.696Z" title="更新于 2021-03-20 18:07:15">2021-03-20</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/">计算机基础</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/C%E8%AF%AD%E8%A8%80%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/">C语言程序设计</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4.8k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>16分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="C语言⭐数据类型"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div><article class="post-content" id="article-container"><h1 id="C语言结构"><a href="#C语言结构" class="headerlink" title="C语言结构"></a>C语言结构</h1><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;  //编译预处理指令</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span>		<span class="comment">//定义主函数 </span></span></span><br><span class="line"><span class="function"></span>&#123;		<span class="comment">//函数开始的标志</span></span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;HelloWorld!&quot;</span>); <span class="comment">//输出语句</span></span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>; 	<span class="comment">//函数执行完毕时返回函数值0</span></span><br><span class="line">&#125;		<span class="comment">//函数结束的标志</span></span><br></pre></td></tr></table></figure>

<ul>
<li>一个程序由一个或多个源程序文件组成。<br>①预处理指令。（#include&lt;stdio.h&gt;)<br>②全局声明。在函数之外进行数据声明，对整个源程序文件范围内有效，在函数中声明的变量为局部变量，只在函数范围内有效。<br>③函数定义。</li>
<li>函数是C程序的主要组成部分。<br>一个C语言程序是由一个或多个函数组成的，其中必须包含一个main函数（有且只有一个main函数）。</li>
<li>一个函数包括两个部分<br>①函数首部<br>即函数第1行，包括函数名、函数类型、函数属性、函数参数名、参数类型。<br>②函数体<br>包含声明部分和执行部分。</li>
<li>程序总是从main函数开始执行的。</li>
<li>程序中对计算机的操作是由函数中的C语言完成的。</li>
<li>在每个数据声明和语句的最后必须有一个分号。</li>
<li>C语言本身不提供输入输出语句。</li>
<li>程序应当包含注释。</li>
</ul>
<h1 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h1><table>
<thead>
<tr>
<th align="center">类型</th>
<th align="center">16位</th>
<th align="center">32位</th>
<th align="center">64位</th>
</tr>
</thead>
<tbody><tr>
<td align="center">char</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">short int</td>
<td align="center">2</td>
<td align="center">2</td>
<td align="center">2</td>
</tr>
<tr>
<td align="center">int</td>
<td align="center">2</td>
<td align="center">4</td>
<td align="center">4</td>
</tr>
<tr>
<td align="center">unsigned int</td>
<td align="center">2</td>
<td align="center">4</td>
<td align="center">4</td>
</tr>
<tr>
<td align="center">float</td>
<td align="center">4</td>
<td align="center">4</td>
<td align="center">4</td>
</tr>
<tr>
<td align="center">double</td>
<td align="center">8</td>
<td align="center">8</td>
<td align="center">8</td>
</tr>
<tr>
<td align="center">long</td>
<td align="center">4</td>
<td align="center">4</td>
<td align="center">8</td>
</tr>
<tr>
<td align="center">long long</td>
<td align="center">8</td>
<td align="center">8</td>
<td align="center">8</td>
</tr>
<tr>
<td align="center">unsigned long</td>
<td align="center">4</td>
<td align="center">4</td>
<td align="center">8</td>
</tr>
</tbody></table>
<h2 id="常量"><a href="#常量" class="headerlink" title="常量"></a>常量</h2><p>在程序运行过程中，其值不能被改变的量称为常量。</p>
<ul>
<li><p>整型常量。如1000，123。<br>①八进制整数：常数前加0进行修饰。如0123。<br>②十六进制整数：常量前加0x作为前缀。如0x123。</p>
</li>
<li><p>实型常量。<br>①十进制小数形式。如123.4，0.3。<br>②指数形式。如12.34e3（代表12.34*10的三次方）</p>
</li>
<li><p>字符常量<br>①普通字符。如’a’,’3’。<br>②转义字符。以字符”&quot;开头的字符序列。</p>
</li>
<li><p>字符串常量。如”China”。</p>
</li>
<li><p>符号常量。用#define指令，指定用一个符号代表一个常量。</p>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># <span class="meta-keyword">define</span> PI 3.1415      <span class="comment">//注意行末没有分号</span></span></span><br></pre></td></tr></table></figure>

<h2 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h2><ul>
<li>变量代表一个有名字的、具有特定属性的一个<code>存储单元</code>，可以用来存放数据，页就是存放变量的值，在程序运行时间，变量的值是可以改变的。 </li>
<li>变量必须<code>先定义，后使用</code>。变量名和变量值是不同的概念，变量名是存储空间的名字，变量值是存放在存储空间的数据。</li>
<li>在编译时，通过变量名找到相应的内存地址，从该存储单元中读取数据。</li>
</ul>
<h2 id="常变量"><a href="#常变量" class="headerlink" title="常变量"></a>常变量</h2><p>C99允许使用<code>常变量</code></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> a=<span class="number">3</span>;</span><br><span class="line"><span class="comment">//a被定义为一个整型变量，指定值为3，而且在变量存在期间其值不能改变。</span></span><br></pre></td></tr></table></figure>
<p>常变量和符号变量的区别</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> PI 3.1415</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">float</span> pi=<span class="number">3.1415</span></span><br></pre></td></tr></table></figure>
<ul>
<li>符号常量使用#define定义，是预编译指令，它是用符号常量代表一个字符串，在预编译时仅是进行字符替换，在预编译后，符号常量就不存在了（全置换为3.1415了），对符号常量是不分配存储单元的。</li>
<li>常变量占用存储单元，有变量值，只是该值不变而已。</li>
</ul>
<h2 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h2><p>标识就是一个对象的名字。</p>
<ul>
<li>C语言规定标识符只能使用<code>字母、数字和下划线</code>组成，且不能以数字开头。</li>
<li>C语言区分大小写，sun和SUM是两个不同的变量。</li>
<li>标识符不能是关键字。</li>
</ul>
<h2 id="整数类型"><a href="#整数类型" class="headerlink" title="整数类型"></a>整数类型</h2><ul>
<li><p>基本整型（int型）<br>编译系统分配给int型数据2个字节或者<code>4</code>个字节（由具体的C编译系统自行决定）。<br>整型在存储单元中的存储方式是：用整数的补码形式存放。<br>一个正数的补码是此数的二进制形式，如5的二进制形式是101，如果用两个字节存放一个整数，则在存储单元中数据形式为 0000 0000 0000 0101。第一个数字为符号位，0代表整数，1代表负数。<br>求负数的补码方法：<strong>先将此数的绝对值写成二进制形式，然后对其后面所有各二进制按位取反，再加1</strong>。如-5：1111 1111 1111 1011。</p>
</li>
<li><p>短整型（short int）<br>int数据4个字节，短整型2个字节，存储方式和int型相同。</p>
</li>
<li><p>长整型（long int)</p>
</li>
<li><p>双长整型（long long int)</p>
<blockquote>
<p>sizeof(short)&lt;=sizeof(int)&lt;=sizeof(long)&lt;=sizeof(long long)</p>
</blockquote>
</li>
<li><p>无符号和有符号<br>有符号(sighed)整型数据存储单元中最高位代表符号（0为正，1为负）。<br>无符号(unsighed)，存储单元中全部二进制都用作存放数值本身，而没有符号。无符号只能存放不带符号的整数，如123，而不能存放负数，如-123。但由于最高位不要来表示符号，而用来表示数值，所以<code>无符号整型变量可以存放的正数范围比一般整型变量中整数的范围扩大一倍</code>。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">signed</span> <span class="keyword">int</span> num=<span class="number">10</span>;  <span class="comment">//signed可以省去</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,num);</span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">int</span> NUM=<span class="number">10</span>;  <span class="comment">//不能为负数</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%u&quot;</span>,NUM);  <span class="comment">//指定用%u格式输出</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="字符型数据"><a href="#字符型数据" class="headerlink" title="字符型数据"></a>字符型数据</h2><p>字符是以<code>整数形式</code>（字符的ASCII代码）存放在内存单元中的。例如</p>
<table>
<thead>
<tr>
<th align="center">字符</th>
<th align="center">ASCII代码</th>
<th align="center">二进制形式</th>
</tr>
</thead>
<tbody><tr>
<td align="center">A</td>
<td align="center">65</td>
<td align="center">1000001</td>
</tr>
<tr>
<td align="center">a</td>
<td align="center">97</td>
<td align="center">1100001</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">49</td>
<td align="center">0110001</td>
</tr>
<tr>
<td align="center">%</td>
<td align="center">32</td>
<td align="center">0100000</td>
</tr>
<tr>
<td align="center">%</td>
<td align="center">37</td>
<td align="center">0100101</td>
</tr>
<tr>
<td align="center">\n</td>
<td align="center">10</td>
<td align="center">0001010</td>
</tr>
</tbody></table>
<p>可以看到，以上的字符的ASCII代号码最多用<code>7个二进制</code>就可以表示。所有，在C中，**<em>指定一个字节(8位)存储一个字符**</em>。此时，字节中第一位置为0，如“a”十进制数97，二进制数为0110 0001。</p>
<blockquote>
<p>字符‘1’只是代表一个形状为1的符号，在需要时按原样输出，在内存中以ASCII码形式存储，占1个字节。整数1是以整数形式存储方式（以二进制补码方式）存储的，占2个或4个字节。</p>
</blockquote>
<p><strong><em><code>字符变量</code></em></strong><br>字符变量用<code>char</code>定义。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">char</span> c=<span class="string">&#x27;?&#x27;</span>;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%d %c\n&quot;</span>,c,c);<span class="comment">// 63 ?</span></span><br><span class="line"><span class="comment">//%d输出整型，%c输出字符，一个字符既可以以字符形式输出，也可以以整型形式输出。</span></span><br><span class="line"><span class="comment">//定义c为字符型变量并使初值为字符&#x27;?&#x27;。&#x27;?&#x27;的ASCII代码是63，系统把整数63赋给变量c。</span></span><br><span class="line"><span class="comment">//c是字符变量，实际上是一个字节的整型变量，由于常用来存放字符，故称为字符变量。</span></span><br><span class="line"><span class="comment">//可以把0~127之间的整数赋给一个字符变量</span></span><br></pre></td></tr></table></figure>

<h2 id="浮点型数据"><a href="#浮点型数据" class="headerlink" title="浮点型数据"></a>浮点型数据</h2><p>浮点型数据是用来<code>表示具有小数点的实数</code>的。在C语言中，实数是以<code>指数形式</code>存放在存储单元中的。一个实数表示为指数可以有不止一种形式，如3.14159可以表示为：3.14159<em>10^0,0.314159</em>10^1,0.0314159<em>10^2等，可以看到：小数点的位置是可以在314159几个数字之间和之前或之后浮点的，只要在小数点位置浮动的同时改变指数的值，就可以保证其指不变。由于小数点位置可以浮点，所以实数的指数形式称为**</em><code>浮点数</code>***。</p>
<blockquote>
<p>规范化指数形式：小数部分中小数点前的数字为0、小数点后第1位数字不为0的表示形式。如0.1314159*10^1。</p>
</blockquote>
<p>浮点数类型包括float(单精度浮点型)、double(双精度浮点型)、long double(长双精度浮点型)。</p>
<ul>
<li>float型(单精度浮点型)<br>编译系统为每一个float型变量分配<code>4</code>个字节，数值以规范化的<code>二进制数指数形式</code>存放在存储单元中。存储时，分成小数部分和指数部分两个部分，分别存放。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">float</span> a=<span class="number">3.14159f</span>;<span class="comment">//加f后缀，表示单精度浮点型</span></span><br></pre></td></tr></table></figure>
<ul>
<li><p>double型(双精度浮点型）<br>为了扩大能表示的数值范围，用8个字节存储一个double型数据，可以得到15位有效数字。</p>
</li>
<li><p>long double型(长双精度型)<br>分配16字节。</p>
</li>
</ul>
<h2 id="运算符和表达式"><a href="#运算符和表达式" class="headerlink" title="运算符和表达式"></a>运算符和表达式</h2><ul>
<li>基本的算术运算符</li>
</ul>
<blockquote>
<p>两个实数消除结果为双精度实数，<code>两个整数相除结果为负数</code>，如5/3=1，舍去小数部分。但是，如果除数或被除数中有一个负数，则舍入方向是不固定的。如-5/3可能为-1或者-2。多数C编译系统采取“<code>向零取整</code>”的方法，即5/3=1，-5/3=-1，取整后向零靠拢。</p>
</blockquote>
<ul>
<li>自增、自减运算符<br>作用是使变量的值加1或减1，只能用于变量。常用于循环，使循环变量加1；也用于指针变量，使指针指向下一个地方。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">++i,--i; <span class="comment">//在使用i之前，先使i的值加(减)1，先加后用 </span></span><br><span class="line">i++,i--;  <span class="comment">//在使用i之后，使i的值加(减)1，先用后加</span></span><br><span class="line"><span class="comment">//例i=3</span></span><br><span class="line">j=++i;  <span class="comment">//i的值先变成4，在赋值给j，j的值为4</span></span><br><span class="line">j=i++;  <span class="comment">//先将i的值赋给j，j的值为3，然后i变为4</span></span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/smwikipedia/articles/1229984.html">i++ : 顺序点(sequence point) 与 副作用 (side effect)</a></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a=<span class="number">2</span>,b=<span class="number">3</span>;</span><br><span class="line"><span class="comment">//在执行b+=()+()时++a的值已经是4了,++a的作用就是程序执行进行a=a+1的操作,两个括号使这个过程被执行了两次，所以由3变成4.</span></span><br><span class="line"><span class="comment">//计算机处理这种运算式的时候，不是依次读入每个字符的，而是整体一起读入的，然后再进行变量替换的，两个++a对于计算机而已，就是a自加2次，然后算完的a再进行计算其他优先低的运算符</span></span><br><span class="line">b+=(++a)+(++a);  <span class="comment">//b=b+(++a=3)+(++a=4);//b=3+4+4(到这一步的表达式的时候a值为4，传回的是引用参数类型，最后一个a为4，返回引用两个a都是4)</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,b); <span class="comment">//b=11</span></span><br></pre></td></tr></table></figure>
<h2 id="优先级与结合性"><a href="#优先级与结合性" class="headerlink" title="优先级与结合性"></a><span id="priority">优先级与结合性</span></h2><p>用算术运算符和括号将运算对象（操作符）连接起来的式子称为<code>C算术表达式</code>。如a*b/c-1.5+’a’。</p>
<ul>
<li>优先级<br>按符号优先级顺序执行，例如先乘除后加减。</li>
<li>结合性<br>优先级相同时，算术运算符的结合方向为“从左至右”，例如a-b+c。<br><img src="https://cdn.jsdelivr.net/gh/lzyblog/image@main/2020/12/10/c7a92f12de8994c61d6b12dc1dccc5c6.png"><blockquote>
<p><strong><em>优先级</em></strong><br>赋值运算符  &lt;  &amp;&amp;和||  &lt;  关系运算符  &lt;  算术运算符  &lt;  !(非）</p>
</blockquote>
</li>
</ul>
<h2 id="强制类型转换"><a href="#强制类型转换" class="headerlink" title="强制类型转换"></a>强制类型转换</h2><p>可以利用强制类型转换运算符将一个表达式转换为所需类型。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">(<span class="keyword">double</span>)a;</span><br><span class="line">(<span class="keyword">int</span>)(x+y);</span><br><span class="line">(<span class="keyword">float</span>)(<span class="number">5</span>%<span class="number">3</span>);</span><br></pre></td></tr></table></figure>
<blockquote>
<p>强制类型转换时，得到一个所需类型的中间数据，而原来变量的类型未发生变化。</p>
</blockquote>
<h2 id="C运算符"><a href="#C运算符" class="headerlink" title="C运算符"></a>C运算符</h2><table>
<thead>
<tr>
<th>C运算符</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>算术运算符</td>
<td>+  -  *  / % ++  –</td>
</tr>
<tr>
<td>关系运算符</td>
<td>&gt; &lt; == &gt;= &lt;= !=</td>
</tr>
<tr>
<td>逻辑运算符</td>
<td>！ &amp;&amp; ||</td>
</tr>
<tr>
<td>位运算符</td>
<td>&lt;&lt;   &gt;&gt;  ~ | ^ &amp;</td>
</tr>
<tr>
<td>赋值运算符</td>
<td>=</td>
</tr>
<tr>
<td>条件运算符</td>
<td>?:</td>
</tr>
<tr>
<td>逗号运算符</td>
<td>,</td>
</tr>
<tr>
<td>指针运算符</td>
<td>*和&amp;</td>
</tr>
<tr>
<td>求字节数运算符</td>
<td>sizeof</td>
</tr>
<tr>
<td>强制类型转换运算符</td>
<td>(类型)</td>
</tr>
<tr>
<td>成员运算符</td>
<td>.  -&gt;</td>
</tr>
<tr>
<td>下标运算符</td>
<td>[]</td>
</tr>
<tr>
<td>其他</td>
<td>如函数调用运算符()</td>
</tr>
</tbody></table>
<h2 id="C语句"><a href="#C语句" class="headerlink" title="C语句"></a>C语句</h2><p>语句的作用是向计算机系统发出操作指令，要求执行相应的操作。</p>
<ul>
<li>控制语句</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>()...<span class="keyword">else</span>... <span class="comment">//条件语句</span></span><br><span class="line"><span class="keyword">for</span>()...       <span class="comment">//循环语句</span></span><br><span class="line"><span class="keyword">while</span>()...     <span class="comment">//循环语句</span></span><br><span class="line"><span class="keyword">do</span>...<span class="keyword">while</span>()   <span class="comment">//循环语句</span></span><br><span class="line"><span class="keyword">continue</span>       <span class="comment">//结束本次循环语句</span></span><br><span class="line"><span class="keyword">break</span>		   <span class="comment">//中止循环语句</span></span><br><span class="line"><span class="keyword">switch</span>         <span class="comment">//多分支选择语句</span></span><br><span class="line"><span class="keyword">return</span>         <span class="comment">//返回语句</span></span><br><span class="line"><span class="keyword">goto</span>           <span class="comment">//转向语句，在结构化程序中基本不用goto语句</span></span><br></pre></td></tr></table></figure>
<ul>
<li>函数调用语句<br>由一个函数调用加分号构成</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;This is a c statement&quot;</span>);</span><br></pre></td></tr></table></figure>
<ul>
<li>表达式语句<br>一个表达式的最后加一个分号</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">i++    <span class="comment">//表达式</span></span><br><span class="line">i++;   <span class="comment">//表达式语句</span></span><br></pre></td></tr></table></figure>
<ul>
<li>空语句<br>只有一个分号，可以用来作为流程的转向点或者循环语句中的循环体。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">;</span><br></pre></td></tr></table></figure>
<ul>
<li>复合语句<br>使用{}把一些语句和声明语句括起来称为复合语句</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line"><span class="keyword">float</span> pi=<span class="number">3.14</span>,r=<span class="number">2.5</span>,area;</span><br><span class="line">area=pi*r*r;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;area=%f&quot;</span>,area);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="赋值语句"><a href="#赋值语句" class="headerlink" title="赋值语句"></a>赋值语句</h2><ul>
<li><p>赋值运算符(=)</p>
</li>
<li><p>复合赋值运算符<br>在赋值符(=)之前加上其他运算符。例如+=,-=,*=,/=，%</p>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">a+=<span class="number">3</span>;    <span class="comment">//等价于 a=a+3</span></span><br><span class="line">x*=y+<span class="number">8</span>;  <span class="comment">//等价于 x=x*(y+3)</span></span><br><span class="line">x%=<span class="number">3</span>;    <span class="comment">//等价于 x=x%3</span></span><br></pre></td></tr></table></figure>
<ul>
<li>赋值表达式<br>由赋值运算符将一个变量和表达式连接起来。<br>赋值运算符左侧值称为左值，左值不能为表达式和常量，而应该是变量。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">a=(b=<span class="number">3</span>*<span class="number">4</span>);  <span class="comment">//正确</span></span><br><span class="line">(a=b)=<span class="number">3</span>*<span class="number">4</span>; <span class="comment">//不正确</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,a=b);<span class="comment">//可以在printf函数中完成赋值和输出</span></span><br></pre></td></tr></table></figure>
<ul>
<li><p>赋值过程中的类型转换<br>① 浮点型数据赋给整型变量时，先对浮点数取整，即舍弃小数部分，然后赋予整型变量。</p>
<pre><code>  int i=3.56;//i=3</code></pre>
<p>②整型数据赋给单、双精度变量时，数值不变，但以浮点数形式存储到变量中。</p>
<pre><code>  float f=23;  //先转换成23.0，再按指数形式存储</code></pre>
<p>③double型赋值给float变量时，先将双精度转换为单精度，即只取6~7位有效数字，存储到float变量的4个字节中，float型赋值给double变量时，数值不变，在内存中以8个字节存储，有效位数扩展到15位。<br>④字符型赋值给整型变量时，将字符的ASCII代码赋给整型变量。</p>
<pre><code>  int i=&#39;A&#39;; //i=65</code></pre>
<p>⑤将一个占字节多的整型数据赋给一个占字节少的整型变量或字符变量，只将其低字节原封不动地送到被赋值的变量（即发生“截断”）。</p>
<pre><code>  int i=289;
  char c=&#39;a&#39;;
  c=i;   //c的值为33，如果用%c输出，即字符“！”。
  //因为整型是4字节，字符型是1字节，所以只取得了int型变量值289二进制最后8位，即0010 0001，为33。</code></pre>
</li>
<li><p>赋值表达式和赋值语句</p>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">max=a   <span class="comment">//赋值表达式，末尾没有分号</span></span><br><span class="line">max=a;	<span class="comment">//赋值语句</span></span><br></pre></td></tr></table></figure>

<h1 id="输入输出"><a href="#输入输出" class="headerlink" title="输入输出"></a>输入输出</h1><ul>
<li><p>所谓输入输出是以<code>计算机主机</code>为主体而言的。从计算机向输出设备（如显示器、打印机等）输出数据称为<code>输出</code>，从输入设备（如键盘、磁盘、光盘等）向计算机输入数据称为<code>输入</code>。</p>
</li>
<li><p>C语言本身不提供输入输出语句，输入输出操作是由C标准函数库中的函数来实现的。printf和<br>scanf不是C语言的关键字，而是库函数的名字。</p>
</li>
<li><p>在使用系统库函数时，要在程序开头用预处理指令#include把有关头文件放到本程序中。</p>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="comment">//#include是将所需要的“头文件”包括到源文件中。</span></span><br><span class="line"><span class="comment">//stido是standard input&amp;output(标准输入和输出)的缩写。</span></span><br><span class="line"><span class="comment">//.h是header的缩写</span></span><br><span class="line"><span class="comment">//此语句的意思就是将stido.h头文件的内容调出来取代本行的#include指令。</span></span><br></pre></td></tr></table></figure>

<h2 id="printf"><a href="#printf" class="headerlink" title="printf()"></a>printf()</h2><ul>
<li><p><strong><em>printf(格式控制，输出序列);</em></strong></p>
</li>
<li><p>格式控制<br>①格式声明：由%和格式字符组成。如%d，作用是将数据指定格式输出。<br>②普通字符：需要按原样输出。</p>
</li>
<li><p>输出列表<br>程序需要输出的数据，可以是常量、变量或表达式。</p>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;a=%d b=%d\n&quot;</span>,a,b);</span><br></pre></td></tr></table></figure>
<blockquote>
<p>printf是函数，因此格式控制和输出序列但是函数的参数。</p>
</blockquote>
<h2 id="格式字符"><a href="#格式字符" class="headerlink" title="格式字符"></a>格式字符</h2><ul>
<li><strong><em>d格式符</em></strong></li>
</ul>
<p>用来输出一个有符号的十进制整数。<br>输出时可以指定数据的<code>域宽（即所占列数）</code>，如%5d，指定输出占5列，输出的数据在此5列区域的<code>右侧</code>。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%5d\n%5d\n&quot;</span>,<span class="number">12</span>,<span class="number">-134</span>);</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">   12  //12前有3个空格 </span></span><br><span class="line"><span class="comment"> -134  //-134前有1个空格</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>输出long(长整型)：<code>%ld</code><br>输出long long(双长整型)：<code>%lld</code></p>
</blockquote>
<ul>
<li><strong><em>c格式符</em></strong></li>
</ul>
<p>用来输出一个字符。也可在指定域宽。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cahr ch=<span class="string">&#x27;a&#x27;</span>;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,a);</span><br></pre></td></tr></table></figure>
<blockquote>
<p>一个整数，如果在0~127范围中，也可以使用%c输出字符形式。系统会将整数作为ASCII码转换成相应字符输出。</p>
</blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">short</span> a=<span class="number">121</span>;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,a);  <span class="comment">//输出y</span></span><br><span class="line"><span class="keyword">int</span> a=<span class="number">377</span>;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,a);<span class="comment">//输出y</span></span><br><span class="line"><span class="comment">// 当整数比较大时，会按其最后一个字节(8位)的信息以字符形式输出。</span></span><br><span class="line"><span class="comment">//377最后一个字节信息是0111 1001，即十进制的121，是y的ASCII码。</span></span><br></pre></td></tr></table></figure>
<ul>
<li><strong><em>s格式符</em></strong></li>
</ul>
<p>用来输出一个字符串。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%s&quot;</span>,<span class="string">&quot;CHINA&quot;</span>);</span><br></pre></td></tr></table></figure>
<ul>
<li><strong><em>f格式符</em></strong></li>
</ul>
<p>用来输出实数（包括单双精度、长双精度），以小数形式输出。</p>
<p>①基本型，用%f<br>不指定输出长度，则系统默认：<code>实数中整数部分全部输出，小数部分输出6位。</code></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">double</span> a=<span class="number">1.0</span>;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;%l\n&quot;</span>,a/<span class="number">3</span>);  <span class="comment">// 0.333333 a虽然是双精度，但使用%l只能输出6位小数</span></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>②指定数据宽度和小数位数，用**<em>%<code>m</code>.<code>n</code>f**</em>。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//对上例a的值指定宽度和小数位数输出</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%20.15f\n&quot;</span>,a/<span class="number">3</span>);</span><br><span class="line"><span class="comment">//   0.333333333333333 注意0前面有3个空间</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>一个双精度只能保证<code>15位</code>有效数值，单精度只能保证<code>6位</code>有效数字。</p>
</blockquote>
<p>③ 输出的数据向左对齐，用%-m.nf。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">printf</span>(%<span class="number">-25.15f</span>,%<span class="number">25.15f</span>\n<span class="string">&quot;,a,a);</span></span><br><span class="line"><span class="string">// 3333.333333333333500     ,     3333.333333333333500（空白处为5个空格）</span></span><br></pre></td></tr></table></figure>
<ul>
<li>e格式符<br>%e指定以指数形式输出实数。</li>
<li>i格式符<br>%i与%d相同。</li>
<li>o格式符<br>%o以八进制整数形式输出。</li>
<li>x格式符<br>%x以十六进制数形式输出整数。</li>
<li>u格式符<br>%u输出无符号（unsigned）型数据，以十进制整数形式输出。</li>
<li>g格式符<br>%g用来输出浮点数。</li>
<li>% 附加字符 格式字符<br>双%输出一个%<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">printf</span>(<span class="string">&quot;%f%%%\n&quot;</span>,<span class="number">1.0</span>/<span class="number">3</span>);</span><br><span class="line"><span class="comment">//0.333333%</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="scanf"><a href="#scanf" class="headerlink" title="scanf()"></a>scanf()</h2><p><strong><em>scanf(格式控制，地址列表)</em></strong><br>格式控制同printf一样，地址列表是由若干个地址组成的表列，可以是<code>变量的地址或字符串的首地址</code>。</p>
<ul>
<li>格式控制后面应当是变量地址，不是变量名。</li>
<li>输入数据顺序应与格式控制一一对应。</li>
<li>输入空格、回车、Tab键或遇非法字符（不属于数值的字符）则认为该数据结束。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sacnf(<span class="string">&quot;a=%f,b=%f,c=%f&quot;</span>,&amp;a,&amp;b,&amp;c); <span class="comment">//在输入时应输入a=1,b=3,c=2 一一对应</span></span><br></pre></td></tr></table></figure>

<h2 id="字符输入输出"><a href="#字符输入输出" class="headerlink" title="字符输入输出"></a>字符输入输出</h2><ul>
<li><strong><em>putchar输出一个字符</em></strong><br><code>putchar(c)</code><br>c可以是字符或者整型（0~127）,也可以输出转义字符。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">char</span> a=<span class="string">&#x27;B&#x27;</span>,b=<span class="string">&#x27;O&#x27;</span>,c=<span class="string">&#x27;Y&#x27;</span>;</span><br><span class="line">	<span class="built_in">putchar</span>(a);</span><br><span class="line">	<span class="built_in">putchar</span>(b);</span><br><span class="line">	<span class="built_in">putchar</span>(c);</span><br><span class="line">	<span class="built_in">putchar</span>(<span class="string">&#x27;\n&#x27;</span>);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//BOY</span></span><br></pre></td></tr></table></figure>
<ul>
<li><strong><em>getchar输入一个字符</em></strong><br><code>getchar()</code><br>getchar函数没有参数，只能接收一个字符，并且可以接收屏幕上无法显示的字符，如转义字符。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">char</span> a,b,c;</span><br><span class="line">	a=getchar();</span><br><span class="line">	b=getchar();</span><br><span class="line">	c=getchar();</span><br><span class="line">	<span class="built_in">putchar</span>(a);</span><br><span class="line">	<span class="built_in">putchar</span>(b);</span><br><span class="line">	<span class="built_in">putchar</span>(c);</span><br><span class="line">	<span class="built_in">putchar</span>(<span class="string">&#x27;\n&#x27;</span>);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>输入信息时，并不是在键盘上输入一个字符就立即送到计算机中去，这些字符先暂存在键盘的<code>缓冲区</code>，只有按了<code>Enter</code>键才把这些字符输入到计算机中去。</p>
</blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">char</span> c1,c2;</span><br><span class="line">	c1=getchar();</span><br><span class="line">	c2=c1+<span class="number">32</span>;     <span class="comment">//大写转小写</span></span><br><span class="line">	purchar(c2);</span><br><span class="line">	<span class="built_in">putchar</span>(<span class="string">&#x27;\n&#x27;</span>);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">小李博客</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://xiaoliblog.cn">https://xiaoliblog.cn</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://xiaoliblog.cn" target="_blank">小李博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/C%E8%AF%AD%E8%A8%80/">C语言</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.png" target="_blank"><img class="post-qr-code-img" src="/img/wechat.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/img/alipay.png" target="_blank"><img class="post-qr-code-img" src="/img/alipay.png" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/page/C07.html"><img class="prev-cover" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png" onerror="onerror=null;src='https://cdn.jsdelivr.net/gh/lzyblog/image@main/2020/11/19/bd16b394f7359083b1f6072a67e3f968.png'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">C语言⭐选择循环</div></div></a></div><div class="next-post pull-right"><a href="/page/CDN0115.html"><img class="next-cover" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@d28761085aa971674b6d1bdfcd6e65e2e27179e1/2021/01/24/8640b5ec587f17b71e725c93a4ea84a7.png" onerror="onerror=null;src='https://cdn.jsdelivr.net/gh/lzyblog/image@main/2020/11/19/bd16b394f7359083b1f6072a67e3f968.png'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">CDN配置&amp;JsDeliver加速</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/page/C01.html" title="C语言⭐函数"><img class="cover" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-15</div><div class="title">C语言⭐函数</div></div></a></div><div><a href="/page/C02.html" title="C语言⭐结构体与共用体"><img class="cover" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-15</div><div class="title">C语言⭐结构体与共用体</div></div></a></div><div><a href="/page/C07.html" title="C语言⭐选择循环"><img class="cover" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-15</div><div class="title">C语言⭐选择循环</div></div></a></div><div><a href="/page/C05.html" title="C语言⭐数组"><img class="cover" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-15</div><div class="title">C语言⭐数组</div></div></a></div><div><a href="/page/C06.html" title="C语言⭐文件操作"><img class="cover" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-15</div><div class="title">C语言⭐文件操作</div></div></a></div><div><a href="/page/C03.html" title="C语言⭐链表"><img class="cover" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@fff8980be0a0a61730b5e88d4d6f406bf5191498/2021/01/24/31920816149c9a437f68045ddbd9bc8b.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-15</div><div class="title">C语言⭐链表</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@6b5e7ef72be1c8973d94e5a9c49accbf775ad820/2021/02/01/c485da031fe0e464d04eaba8a66c4a8f.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">小李博客</div><div class="author-info__description">越努力，越幸运！</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">210</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">38</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">56</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xiaoliblog"><i class="fab fa-github"></i><span>博主的GitHub首页</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/xiaoliblog" target="_blank" title="Gitee"><i class="iconfont icon-gitee card_icon_gitee"></i></a><a class="social-icon" href="https://space.bilibili.com/390969485" target="_blank" title="BiliBili"><i class="iconfont icon-bilibili card_icon_bilibili"></i></a><a class="social-icon" href="http://wpa.qq.com/msgrd?v=3&amp;uin=2312057536&amp;site=CSDN&amp;menu=yes" target="_blank" title="QQ"><i class="iconfont icon-qq card_icon_qq"></i></a><a class="social-icon" href="https://github.com/xiaoliblog" target="_blank" title="GitHub"><i class="iconfont icon-git card_icon_git"></i></a><a class="social-icon" href="https://blog.csdn.net/qq_43266250?spm=1010.2135.3001.5113" target="_blank" title="CSDN"><i class="iconfont icon-csdn card_icon_csdn"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">正在考研备考中💦</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#C%E8%AF%AD%E8%A8%80%E7%BB%93%E6%9E%84"><span class="toc-number">1.</span> <span class="toc-text">C语言结构</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.</span> <span class="toc-text">数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E9%87%8F"><span class="toc-number">2.1.</span> <span class="toc-text">常量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%98%E9%87%8F"><span class="toc-number">2.2.</span> <span class="toc-text">变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E5%8F%98%E9%87%8F"><span class="toc-number">2.3.</span> <span class="toc-text">常变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A0%87%E8%AF%86%E7%AC%A6"><span class="toc-number">2.4.</span> <span class="toc-text">标识符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B4%E6%95%B0%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.5.</span> <span class="toc-text">整数类型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E5%9E%8B%E6%95%B0%E6%8D%AE"><span class="toc-number">2.6.</span> <span class="toc-text">字符型数据</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%AE%E7%82%B9%E5%9E%8B%E6%95%B0%E6%8D%AE"><span class="toc-number">2.7.</span> <span class="toc-text">浮点型数据</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%90%E7%AE%97%E7%AC%A6%E5%92%8C%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">2.8.</span> <span class="toc-text">运算符和表达式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BC%98%E5%85%88%E7%BA%A7%E4%B8%8E%E7%BB%93%E5%90%88%E6%80%A7"><span class="toc-number">2.9.</span> <span class="toc-text">优先级与结合性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%BA%E5%88%B6%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-number">2.10.</span> <span class="toc-text">强制类型转换</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#C%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.11.</span> <span class="toc-text">C运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#C%E8%AF%AD%E5%8F%A5"><span class="toc-number">2.12.</span> <span class="toc-text">C语句</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B5%8B%E5%80%BC%E8%AF%AD%E5%8F%A5"><span class="toc-number">2.13.</span> <span class="toc-text">赋值语句</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA"><span class="toc-number">3.</span> <span class="toc-text">输入输出</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#printf"><span class="toc-number">3.1.</span> <span class="toc-text">printf()</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A0%BC%E5%BC%8F%E5%AD%97%E7%AC%A6"><span class="toc-number">3.2.</span> <span class="toc-text">格式字符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#scanf"><span class="toc-number">3.3.</span> <span class="toc-text">scanf()</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA"><span class="toc-number">3.4.</span> <span class="toc-text">字符输入输出</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/page/project01.html" title="前端实例🥳响应式网站首页"><img src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@c19917500ab083c77c7613263ba7ee74d5a08ae6/2021/04/30/469f30b141d73fa0fc4c962662d5813f.png" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/lzyblog/image@main/2020/11/19/bd16b394f7359083b1f6072a67e3f968.png'" alt="前端实例🥳响应式网站首页"/></a><div class="content"><a class="title" href="/page/project01.html" title="前端实例🥳响应式网站首页">前端实例🥳响应式网站首页</a><time datetime="2021-04-30T11:50:53.094Z" title="发表于 2021-04-30 19:50:53">2021-04-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/page/WeChatpay.html" title="微信支付对接"><img src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@f2f670b92ea149650ffa7834354fc90284f2f44a/2021/04/29/5bdc9b381a06193d27cf2fb7c2fb608a.png" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/lzyblog/image@main/2020/11/19/bd16b394f7359083b1f6072a67e3f968.png'" alt="微信支付对接"/></a><div class="content"><a class="title" href="/page/WeChatpay.html" title="微信支付对接">微信支付对接</a><time datetime="2021-04-29T12:20:48.070Z" title="发表于 2021-04-29 20:20:48">2021-04-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/page/Alipay.html" title="支付宝支付对接"><img src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@61a9b6a6e09e4bda38bb08e3104b717885beaee5/2021/04/29/c3fa51f9cf14e90d9e5a7aa8814dd041.png" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/lzyblog/image@main/2020/11/19/bd16b394f7359083b1f6072a67e3f968.png'" alt="支付宝支付对接"/></a><div class="content"><a class="title" href="/page/Alipay.html" title="支付宝支付对接">支付宝支付对接</a><time datetime="2021-04-27T16:00:00.000Z" title="发表于 2021-04-28 00:00:00">2021-04-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/page/Vuejs11.html" title="Vue.js前端框架🎯Pagination+PageHelper实现分页"><img src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@61bf4245f6d84d2d0f66d163b89c916788cc1845/2021/04/13/ec6b232f8fe5a840e4bd8c3eabcf49b2.png" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/lzyblog/image@main/2020/11/19/bd16b394f7359083b1f6072a67e3f968.png'" alt="Vue.js前端框架🎯Pagination+PageHelper实现分页"/></a><div class="content"><a class="title" href="/page/Vuejs11.html" title="Vue.js前端框架🎯Pagination+PageHelper实现分页">Vue.js前端框架🎯Pagination+PageHelper实现分页</a><time datetime="2021-04-26T14:48:39.701Z" title="发表于 2021-04-26 22:48:39">2021-04-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/page/Vuejs10.html" title="Vue.js前端框架🎯Vue-Element-admin模版"><img src="https://cdn.jsdelivr.net/gh/xiaoliblog/image@61bf4245f6d84d2d0f66d163b89c916788cc1845/2021/04/13/ec6b232f8fe5a840e4bd8c3eabcf49b2.png" onerror="this.onerror=null;this.src='https://cdn.jsdelivr.net/gh/lzyblog/image@main/2020/11/19/bd16b394f7359083b1f6072a67e3f968.png'" alt="Vue.js前端框架🎯Vue-Element-admin模版"/></a><div class="content"><a class="title" href="/page/Vuejs10.html" title="Vue.js前端框架🎯Vue-Element-admin模版">Vue.js前端框架🎯Vue-Element-admin模版</a><time datetime="2021-04-19T16:00:00.000Z" title="发表于 2021-04-20 00:00:00">2021-04-20</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 小李博客</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">🎯Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">🎉Butterfly</a></div><div class="footer_custom_text"><span><a style="margin-inline:5px" target="_blank" href="https://hexo.io/"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为Hexo"></a><a style="margin-inline:5px" target="_blank" href="https://butterfly.js.org/"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题采用butterfly"></a><a style="margin-inline:5px" target="_blank" href="https://www.jsdelivr.com/"><img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr" title="本站使用JsDelivr为静态资源提供CDN加速"></a><a style="margin-inline:5px" target="_blank" href="https://vercel.com/ "><img src="https://img.shields.io/badge/Hosted-Vercel-brightgreen?style=flat&logo=Vercel" title="本站采用双线部署，默认线路托管于Vercel"></a><a style="margin-inline:5px" target="_blank" href="https://coding.net/ "><img src="https://img.shields.io/badge/Hosted-Coding-0cedbe?style=flat&logo=Codio" title="本站采用双线部署，联通线路托管于Coding"></a><a style="margin-inline:5px" target="_blank" href="https://github.com/"><img src="https://img.shields.io/badge/Source-Github-d021d6?style=flat&logo=GitHub" title="本站项目由Gtihub托管"></a><a style="margin-inline:5px" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&logo=Claris" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a></span></div><div class="icp"><a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/"><img class="icp-icon" src="/img/icp.png" alt="ICP"/><span>湘ICP备2021002541号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="algolia-search"><div class="search-dialog"><div class="search-dialog__title" id="algolia-search-title">Algolia</div><div id="algolia-input-panel"><div id="algolia-search-input"></div></div><hr/><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-stats"></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script><script src="/js/main.js"></script><script defer src="/js/tw_cn.js"></script><script defer src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module" defer></script><script defer src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script defer src="/js/search/algolia.js"></script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    loader: {
      source: {
        '[tex]/amsCd': '[tex]/amscd'
      }
    },
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        addClass: [200,() => {
          document.querySelectorAll('mjx-container:not([display=\'true\']').forEach( node => {
            const target = node.parentNode
            if (!target.classList.contains('has-jax')) {
              target.classList.add('mathjax-overflow')
            }
          })
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      false && mermaid.init()
    })
  }
}</script><script>(()=>{
  const $countDom = document.getElementById('twikoo-count')
  const init = () => {
    twikoo.init(Object.assign({
      el: '#twikoo-wrap',
      envId: 'xiaoliblog-8gj3j5045d5b0896',
      region: ''
    }, null))
  }

  const getCount = () => {
    twikoo.getCommentsCount({
      envId: 'xiaoliblog-8gj3j5045d5b0896',
      region: '',
      urls: [window.location.pathname],
      includeReply: false
    }).then(function (res) {
      $countDom.innerText = res[0].count
    }).catch(function (err) {
      console.error(err);
    });
  }

  const loadTwikoo = (bool = false) => {
    if (typeof twikoo === 'object') {
      init()
      bool && $countDom && setTimeout(getCount,0)
    } else {
      getScript('https://cdn.jsdelivr.net/npm/twikoo@1.3.0/dist/twikoo.all.min.js').then(()=> {
        init()
        bool && $countDom && setTimeout(getCount,0)
      })
    }
  }

  if ('Twikoo' === 'Twikoo' || !true) {
    if (true) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
    else loadTwikoo(true)
  } else {
    window.loadOtherComment = () => {
      loadTwikoo()
    }
  }
})()</script></div><script defer src="//lib.baomitu.com/jquery/3.5.1/jquery.min.js"></script><script defer src="https://myhkw.cn/api/player/160561664166" id="myhk" key="160561664166" m="1"></script><div><canvas id="snow" style="position:fixed;top:0;left:0;width:100%;height:100%;z-index:99999;pointer-events:none"></canvas></div><script>const notMobile = (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)));</script><scrip async type="text/javascript" src="https://cdn.jsdelivr.net/gh/Candinya/Kratos-Rebirth@latest/source/js/snow.min.js"></scrip><scrip defer src="https://cdn.jsdelivr.net/npm/hexo-theme-volantis@latest/source/js/issues.min.js"></scrip><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><script>var gitcalendar = new Vue({
  el: '#gitcalendar',
  data: {
    simplemode: true, 
    user: 'xiaoliblog',
    fixed: 'fixed',
    px: 'px',
    x: '',
    y: '',
    span1: '',
    span2: '',
    month: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
    monthchange: [],
    oneyearbeforeday: '',
    thisday: '',
    amonthago: '',
    aweekago: '',
    weekdatacore: 0,
    datacore: 0,
    total: 0,
    datadate: '',
    data: [],
    positionplusdata: [],
    firstweek: [],
    lastweek: [],
    beforeweek: [],
    thisweekdatacore: 0,
    mounthbeforeday: 0,
    mounthfirstindex: 0,
    crispedges: 'crispedges',
    thisdayindex: 0,
    amonthagoindex: 0,
    amonthagoweek: [],
    firstdate: [],
    first2date: [],
    montharrbefore: [],
    monthindex: 0,
    color: ['#ebedf0', '#f1f8ff', '#dbedff', '#c8e1ff', '#79b8ff', '#2188ff', '#0366d6', '#005cc5', '#044289', '#032f62', '#05264c']
  },
  methods: {
    selectStyle(data, event) {
      document.querySelector('.angle-wrapper').style.display = 'block'
      this.span1 = data.date;
      this.span2 = data.count;
      this.x = event.clientX - 100;
      this.y = event.clientY - 60
    },
    outStyle() {
      document.querySelector('.angle-wrapper').style.display = 'none'
    },
    thiscolor(x) {
      if (x === 0) {
        let i = parseInt(x / 2);
        return this.color[0]
      } else if (x < 2) {
        return this.color[1]
      } else if (x < 20) {
        let i = parseInt(x / 2);
        return this.color[i]
      } else {
        return this.color[9]
      }
    },
  }
});
var apiurl = 'python-github-calendar-api-ruby.vercel.app' ? 'https://python-github-calendar-api-ruby.vercel.app/api?' : 'https://githubapi.ryanchristian.dev/user/'
var githubapiurl = apiurl + gitcalendar.user;
//canvas绘图
function responsiveChart() {
  let c = document.getElementById("gitcanvas");
  if (c) {
    let cmessage = document.getElementById("gitmessage");
    let ctx = c.getContext("2d");
    c.width = document.getElementById("gitcalendarcanvasbox").offsetWidth;
    let linemaxwitdh = 0.96 * c.width / gitcalendar.data.length;
    c.height = 9 * linemaxwitdh;
    let lineminwitdh = 0.8 * linemaxwitdh;
    let setposition = {
      x: 0.02 * c.width,
      y: 0.025 * c.width
    };
    for (let week in gitcalendar.data) {
      weekdata = gitcalendar.data[week];
      for (let day in weekdata) {
        let dataitem = {
          date: "",
          count: "",
          x: 0,
          y: 0
        };
        gitcalendar.positionplusdata.push(dataitem);
        ctx.fillStyle = gitcalendar.thiscolor(weekdata[day].count);
        setposition.y = Math.round(setposition.y * 100) / 100;
        dataitem.date = weekdata[day].date;
        dataitem.count = weekdata[day].count;
        dataitem.x = setposition.x;
        dataitem.y = setposition.y;
        ctx.fillRect(setposition.x, setposition.y, lineminwitdh, lineminwitdh);
        setposition.y = setposition.y + linemaxwitdh
      };
      setposition.y = 0.025 * c.width;
      setposition.x = setposition.x + linemaxwitdh
    };
    ctx.font = "600  Arial";
    ctx.fillStyle = '#aaa';
    ctx.fillText("日", 0, 1.9 * linemaxwitdh);
    ctx.fillText("二", 0, 3.9 * linemaxwitdh);
    ctx.fillText("四", 0, 5.9 * linemaxwitdh);
    ctx.fillText("六", 0, 7.9 * linemaxwitdh);
    let monthindexlist = c.width / 24;
    for (let index in gitcalendar.monthchange) {
      ctx.fillText(gitcalendar.monthchange[index], monthindexlist, 0.7 * linemaxwitdh);
      monthindexlist = monthindexlist + c.width / 12
    };
    cmessage.onmousemove = function(event) {
      document.querySelector('.angle-wrapper').style.display = 'none'
    };
    c.onmousemove = function(event) {
      document.querySelector('.angle-wrapper').style.display = 'none'
      getMousePos(c, event);
    };

    function getMousePos(canvas, event) {
      var rect = canvas.getBoundingClientRect();
      var x = event.clientX - rect.left * (canvas.width / rect.width);
      var y = event.clientY - rect.top * (canvas.height / rect.height);
      //console.log("x:"+x+",y:"+y);
      for (let item of gitcalendar.positionplusdata) {
        let lenthx = x - item.x;
        let lenthy = y - item.y;
        //console.log(lenthx,lenthy);
        if (0 < lenthx && lenthx < lineminwitdh) {
          if (0 < lenthy && lenthy < lineminwitdh) {
            //console.log(item.date,item.count)
            document.querySelector('.angle-wrapper').style.display = 'block'
            gitcalendar.span1 = item.date;
            gitcalendar.span2 = item.count;
            gitcalendar.x = event.clientX - 100;
            gitcalendar.y = event.clientY - 60
          }
        }
        //if(0< x - item.x <lineminwitdh&&0< y - item.y <lineminwitdh){
        //console.log(item.count,item.date);
        //}
      }
    }
  }
}
//数据统计算法
function addlastmonth() {
  if (gitcalendar.thisdayindex === 0) {
    thisweekcore(52);
    thisweekcore(51);
    thisweekcore(50);
    thisweekcore(49);
    thisweekcore(48);
    gitcalendar.thisweekdatacore += gitcalendar.firstdate[6].count;
    gitcalendar.amonthago = gitcalendar.firstdate[6].date
  } else {
    thisweekcore(52);
    thisweekcore(51);
    thisweekcore(50);
    thisweekcore(49);
    thisweek2core();
    gitcalendar.amonthago = gitcalendar.first2date[gitcalendar.thisdayindex - 1].date
  }
};

function thisweek2core() {
  for (let i = gitcalendar.thisdayindex - 1; i < gitcalendar.first2date.length; i++) {
    gitcalendar.thisweekdatacore += gitcalendar.first2date[i].count
  }
};

function thisweekcore(index) {
  for (let item of gitcalendar.data[index]) {
    gitcalendar.thisweekdatacore += item.count
  }
};

function addlastweek() {
  for (let item of gitcalendar.lastweek) {
    gitcalendar.weekdatacore += item.count
  }
};

function addbeforeweek() {
  for (let i = gitcalendar.thisdayindex; i < gitcalendar.beforeweek.length; i++) {
    gitcalendar.weekdatacore += gitcalendar.beforeweek[i].count
  }
};

function addweek(data) {
  if (gitcalendar.thisdayindex === 6) {
    gitcalendar.aweekago = gitcalendar.lastweek[0].date;
    addlastweek()
  } else {
    lastweek = data.contributions[51];
    gitcalendar.aweekago = lastweek[gitcalendar.thisdayindex + 1].date;
    addlastweek();
    addbeforeweek()
  }
}

fetch(githubapiurl)
  .then(data => data.json())
  .then(data => {
    gitcalendar.data = data.contributions;
    gitcalendar.total = data.total;
    gitcalendar.first2date = gitcalendar.data[48];
    gitcalendar.firstdate = gitcalendar.data[47];
    gitcalendar.firstweek = data.contributions[0];
    gitcalendar.lastweek = data.contributions[52];
    gitcalendar.beforeweek = data.contributions[51];
    gitcalendar.thisdayindex = gitcalendar.lastweek.length - 1;
    gitcalendar.thisday = gitcalendar.lastweek[gitcalendar.thisdayindex].date;
    gitcalendar.oneyearbeforeday = gitcalendar.firstweek[0].date;
    gitcalendar.monthindex = gitcalendar.thisday.substring(5, 7) * 1;
    gitcalendar.montharrbefore = gitcalendar.month.splice(gitcalendar.monthindex, 12 - gitcalendar.monthindex);
    gitcalendar.monthchange = gitcalendar.montharrbefore.concat(gitcalendar.month);
    addweek(data);
    addlastmonth();
    responsiveChart();
  })
  .catch(function(error) {
    console.log(error);
  });

//手机版更换为svg绘制
if (document.getElementById("gitcalendarcanvasbox").offsetWidth < 500) {
  gitcalendar.simplemode = false
}

//当改变窗口大小时重新绘制canvas
window.onresize = function() {
  if (gitcalendar.simplemode) responsiveChart()
}

//解决滚动滑轮时出现的标签显示
window.onscroll = function() {
  if (document.querySelector('.angle-wrapper')) {
    document.querySelector('.angle-wrapper').style.display = 'none'
  }
};</script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"react":{"opacity":0.7}});</script></body></html>